<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">

<head th:include="include :: header">
</head>
<link rel="stylesheet" th:href="@{/css/yw.css}">

<body class="hold-transition skin-blue sidebar-mini">
<style>
    .table-border tbody tr td{
        border-top: 1px solid black;
    }
</style>
    <section class="content-header">
        <h1>
            项目款票查询
        </h1>
    </section>
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <div class="box">
                    <div class="box-header">
                        <form id="queryForm" onsubmit="return false;">
                            <div class="row">
                                <div class="form-inline">
                                    <div class="form-group" style="margin-right: 10px;">
                                        <label>项目编号 </label>
                                        <input id="contName" name="contName" class="form-control" placeholder="请输入项目编号"
                                            type="text">
                                    </div>
                                    <div class="form-group" style="margin-right: 10px;">
                                        <label>卖方合同编号</label>
                                        <input type="text" name="sellCode" class="form-control" placeholder="请输入卖方合同编号">
                                    </div>
                                    <div class="form-group" style="margin-right: 10px;">
                                        <label>签订日期</label>
                                        <input type="text" class="form-control datepicker" name="beginTime"
                                            placeholder="开始日期" readonly>
                                        至
                                        <input type="text" class="form-control datepicker" name="endTime"
                                            placeholder="结束日期" readonly>

                                    </div>

                                    <div class="form-group" style="margin-right: 10px;">
                                        <label>类别</label>
                                        <select class="form-control" style="margin-right: 10px;" id="leibieEdit"
                                            name="contType">
                                            <option value="" selected="selected">请选择</option>
                                            <option value="对内销售">对内销售</option>
                                            <option value="对内采购">对内采购</option>
                                            <option value="合作制造">合作制造</option>
                                        </select>
                                    </div>
                                    <div class="form-group" style="margin-right: 10px;">
                                        <label style="margin-right: 10px;">回款类型</label>
                                        <select class="form-control" style="margin-right: 10px;" id="huikuanType"
                                            name="returnType">
                                            <option value="" selected="selected">请选择</option>
                                            <option value="已回全">已回全</option>
                                            <option value="未回全">未回全</option>
                                            <option value="有抹账">有抹账</option>
                                            <option value="有坏账">有坏账</option>
                                        </select>
                                    </div>
                                    <div class="form-group" style="margin-right: 10px;">
                                        <label>款票状态</label>
                                        <select class="form-control" style="margin-right: 10px;"
                                            id="kuanpiaozhuangtaiEdit" name="moneyInvoiceStatue">
                                            <option value="" selected="selected">请选择</option>
                                            <option value="0" >未完成</option>
                                            <option value="1">保存未提交</option>
                                            <option value="2">提交未审核</option>
                                            <option value="3">被驳回</option>
                                            <option value="4">已完结</option>
                                        </select>
                                    </div>


                                    <button type="button" class="btn btn-success" id="btn-search"
                                        style="margin-top: 5px;">
                                        <span class="Bold">搜索</span>
                                    </button>
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="box-body">
                        <!--<table  id="bootstrap-table" style="table-layout: fixed;word-break:break-all; word-wrap:break-word;"></table>-->
                        <table class="table-border" id="bootstrap-table"></table>
                    </div>
                </div>
            </div>
        </div>
    </section>
    <div th:include="include :: footer">
    </div>
    <script th:inline="javascript">
        /**
         * 表格搜索
         */
        $("#btn-search").click(function () {
            js.table.search(table);
        });


        $(function () {
            /** 加载用户表格 */
            table = js.table.init({
                url: ctx + "InvoiceList4",
                showColumns: true,
                showExport: true,
                pageSize: 2,
                pagination: false,
                columns: [
                    {
                        title: '序号', field: 'id', width: '50',
                        formatter: function (value, row, index, field) {
                            var pageSize = table.bootstrapTable('getOptions').pageSize;
                            var pageNumber = table.bootstrapTable('getOptions').pageNumber;
                            return pageSize * (pageNumber - 1) + index + 1;
                        }
                    },
                    {
                        title: "项目编号", field: 'contName',
                        formatter: function (value, row, index) {
                            return changeRow(value)
                        }
                    },
                    { title: "类别", field: 'contType' },
                    { title: "买方", field: 'totalMethod' },
                    { title: "业主方", field: 'contPartner' },
                    { title: "卖方<br>合同号", field: 'sellCode' },
                    {
                        title: "签订日期", field: 'contYear',
                        formatter: function (value, row, index) {
                            return changeDateFormat(value)
                        }
                    },
                    { title: "数量", field: 'cnt' },
                    {
                        title: "分包已<br>收金额", field: 'sumAlreadyMoney'
                        , formatter: function (value, row, index) {
                            return isZero(value, row);
                        }
                    },
                    {
                        title: "分包收<br>款比例", field: 'collectionScale',
                        formatter: function (value, row, index) {
                            return changeHundred(value, row);
                        }
                    },
                    {
                        title: "分包已<br>开发票", field: 'sumAlreadyInvoiceAmount'
                        , formatter: function (value, row, index) {
                            return isZero(value, row);
                        }
                    },
                    {
                        title: "分包开<br>票比例", field: 'invoiceScale',
                        formatter: function (value, row, index) {
                            return changeHundred(value, row);
                        }
                    },
                    {
                        title: "应收未收", field: 'conYsws'
                        , formatter: function (value, row, index) {
                            return isZero(value, row);
                        }
                    },
                    {
                        title: "抹账金额", field: 'rmiDebtsMoney',
                        formatter: function (value, row, index) {
                            return isZero(value, row);
                        }
                    },
                    {
                        title: "坏账金额", field: 'rmiBadMoney',
                        formatter: function (value, row, index) {
                            return isZero(value, row);
                        }
                    },
                    {
                        title: "款票状态", field: 'moneyInvoiceStatue', formatter: function (value, row, index) {
                            if (value === 0) {
                                return '<span class="label  badge  label-default">未完成</span>';
                            } else if (value === 1) {
                                return '<span class="label  badge  label-warning">保存未提交</span>';
                            } else if (value === 2) {
                                return '<span class="label  badge  label-primary">提交未审核</span>';
                            } else if (value === 3) {
                                return '<span class="label  badge  label-danger">被驳回</span>';
                            } else if (value === 4) {
                                return '<span class="label  badge  label-success">已完结</span>';
                            }
                        }
                    },
                    {
                        title: "操作", formatter: function (value, row, index) {
                            var actions = [];
                            actions.push('<a class="btn btn-success btn-xs" target="_blank" href="' + ctx + 'kpSelect/contractInfo?conId=' + row.conId + '" > 查看</a> ');
                            return actions.join('');
                        }
                    }
                ]
            });

        })

        /**
         * 百分比转换  保留4位小数
         * @param value
         * @returns {string}
         */
        function changeHundred(value) {
            if (value == null || value == undefined || value === "" || value == "null" || value == 'undefined') {
                return 0 + '%';
            }
            var str = Number(value * 100).toFixed(2);
            str += "%";
            return str;
        }

       
        function isZero(value) {
            if (value == null || value == undefined || value === "" || value == "null" || value == 'undefined') {
                return '0';
            } else if (value == 0 || value == '0') {
                return value;
            }
            else {
                return value;
            }
        }


        /**
         * 日期格式转换
         * @param value
         * @returns {*}
         */
        function changeDateFormat(value) {
            if (value == '' || value == undefined) {
                return "";
            }
            var myDate = new Date(value);
            //获取当前年
            var year = myDate.getFullYear();
            //获取当前月
            var month = myDate.getMonth() + 1;
            month = month < 10 ? "0" + month : month;
            //获取当前日
            var date = myDate.getDate();
            date = date < 10 ? "0" + date : date;
            var h = myDate.getHours();       //获取当前小时数(0-23)
            h = h < 10 ? "0" + h : h;
            var m = myDate.getMinutes();     //获取当前分钟数(0-59)
            m = m < 10 ? "0" + m : m;
            var s = myDate.getSeconds();
            s = s < 10 ? "0" + s : s;
            var time = year + '-' + month + "-" + date;
            return time;
        }

        function changeRow(value) {
            var code = value;
            var code2 = code.replace(/;/g, "<br>");
            return code2.replace(/；/g, "<br>");
        }

    </script>